package com.test.realcityalfa;

import android.os.Bundle;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.actionbarsherlock.view.Menu;
import com.test.realcityalfa.actionbar.ActionBarBuilder;
import com.test.realcityalfa.actionbar.ActionBarMenuBuilder;
import com.test.realcityalfa.actionbar.ActionBarSettings;
import com.test.realcityalfa.actionbar.ActionMenuSettings;
import com.test.realcityalfa.frmwrk.BaseActivity;
import com.test.realcityalfa.frmwrk.DashboardOnClickListener;
import com.test.realcityalfa.frmwrk.LoadAdCountAsyncTask;
import com.test.realcityalfa.json.requests.AdCountRequestBuilder;

public class DashboardActivity extends BaseActivity
{
	ActionBarBuilder barBuilder;
	DashboardOnClickListener clickListener = new DashboardOnClickListener(this);	
	LoadAdCountAsyncTask adCountTask;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.dashboard_activity);		
		setUpActionBar();
		setOnClickListeners();
	}
	
	@Override
	protected void onResume() 
	{
		loadAdCount();
		super.onResume();
	}
	
	protected void setOnClickListeners()
	{
		RelativeLayout item = (RelativeLayout) findViewById(R.id.dashboardFirstItem);
		item.setOnClickListener(clickListener);
	}
	
	@Override
	public boolean onCreateOptionsMenu(Menu menu) 
	{
		
		ActionBarMenuBuilder menuBuilder = new ActionBarMenuBuilder();
		menuBuilder.createMenu(getSupportMenuInflater(), new ActionMenuSettings(R.menu.menu_dashborad, menu));
		return true;
	}
	
	private void setUpActionBar()
	{
		ActionBarBuilder barBuilder = new ActionBarBuilder(this);
		ActionBarSettings barSettings = new ActionBarSettings();
		barSettings.setHomeButtonEnabled(true);
		barSettings.setTitle(getResources().getString(R.string.activityTitle_dashboard));
		barSettings.setVisibility(true);
		barSettings.setMenuResourceId(R.menu.menu_dashborad);
		//barSettings.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);
		barBuilder.applyActionBarSettings(getSupportActionBar(), barSettings);
	}
	
	private void loadAdCount()
	{
		adCountTask = new LoadAdCountAsyncTask(this, new AdCountRequestBuilder());
		adCountTask.setOutpuTextView((TextView)findViewById(R.id.dashboard_AdCount));
		adCountTask.execute();
	}

}
